import {BaseController} from 'egg-cool-controller';
import router from 'egg-cool-router';

/**
 * 应用通用控制器
 */
@router.prefix ('/wx')
export default class WxCommController extends BaseController {

    init () {
        this.setEntity (this.ctx.repo.wx.Wx_user);
        this.setService (this.service.wx.wx);
    }

    /**
     * 登录
     */
    @router.post ('/login')
    public async login () {
        this.res ({data : await this.service.wx.wx.login (this.getBody ())});
    }

    /***
     * 退出登录
     * */
    @router.post ('/logout')
    public async logout () {
        this.res ({data : await this.service.wx.wx.logout ()});
    }

    /**
     * 微信获取小程序二维码createQRCode
     * */
    @router.post ('/createQRCode')
    public async getAccessToken () {
        const result = await this.ctx.service.wx.wx.createQRCode (this.getBody ());
        this.res ({data : result});
    }

    /***
     * 绑定手机
     * **/

    @router.post ('/bindPhone')
    public async bindPhone () {
        const result = await this.ctx.service.wx.wx.decodePhone (this.getBody ());
        console.log (result);
        this.res ({data : result});
    }

    /***
     * 用户信息
     * */
    @router.get ('/user')
    public async user () {
        const result = await this.ctx.service.wx.wx.userInfo ();
        console.log (result);
        this.res ({data : result});
    }
}
